package com.chen.nongansampling.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.chen.nongansampling.activity.OperatorDetailActivity;
import com.chen.nongansampling.app.BaseApplication;
import com.chen.nongansampling.bean.Callback;
import com.chen.nongansampling.bean.getOperatingByPkId;
import com.chen.nongansampling.bean.getOperingByPkIdRequest;
import com.chen.nongansampling.model.CallbackData;
import com.chen.nongansampling.presenter.getOperatingByPkIdPresenter;
import com.chen.nongansampling.presenterView.getoperatingbypkid;

import java.util.ArrayList;
import java.util.List;

public class getOperatingByPkIdFragment extends Fragment implements getoperatingbypkid {
     private getOperatingByPkIdPresenter pr = new getOperatingByPkIdPresenter(getContext());
    private Activity activity;
    private getOperatingByPkIdPresenter samplePresenter=new getOperatingByPkIdPresenter(getContext());
    public static ArrayList<getOperatingByPkId> marketList;
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    public static getOperatingByPkIdFragment newInstance() {
        return new getOperatingByPkIdFragment();
    }
    private String mParam1;
    private String mParam2;
    public static Context  mContext;
    public static String pkid;
    public  getOperatingByPkIdFragment(){

    }
    public  getOperatingByPkIdFragment(Context context){
        this.mContext=context;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }

        pr.onCreate();

        pr.BindPresentView(this);
    }
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
    {
       // super.onViewCreated(view, savedInstanceState);
       // getOperingByPkIdRequest getOperingByPkIdRequest  = new getOperingByPkIdRequest();
       // getOperingByPkIdRequest.setAccountPkId(BaseApplication.getAccount().getPkId());
       // getOperingByPkIdRequest.setPkId("99244715-7b53-4c9a-99c8-23931e10313");
       // System.out.println(getOperingByPkIdRequest.toString());
       // samplePresenter.getOperatingByPkIdPresenterResponseInfo(getOperingByPkIdRequest);
    }

    @Override
    public void onError(String result) {

    }

    @Override
    public void insertOperator(Callback callback) {

    }

    @Override
    public void getOperatorList(Object resultData) {
        CallbackData callbackData=(CallbackData<List<getOperatingByPkId>>)resultData;
        marketList=(ArrayList<getOperatingByPkId>)callbackData.getData();
            System.out.println("mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"+marketList);
        OperatorDetailActivity operatorDetailActivity = new OperatorDetailActivity();
        operatorDetailActivity.show(marketList);
        Intent intent=new Intent(mContext, OperatorDetailActivity.class);
        mContext.startActivity(intent);
    }
    @Override
    public void onResume() {
        super.onResume();
        samplePresenter.BindPresentView(this);
        samplePresenter.onCreate();
        initRequest();

    }

    public  void initRequest(){

      // getOperingByPkIdRequest s=new getOperingByPkIdRequest();
      // s.setAccountPkId(BaseApplication.getAccount().getPkId());
      // s.setPkId(pkid);
      // samplePresenter.getOperatingByPkIdPresenterResponseInfo(s);



    }
    public  void fanhuipkid(String pkid1){
        pkid=pkid1;

    }

    public List<getOperatingByPkId> zhi(String pkid1){
        getOperingByPkIdRequest getOperingByPkIdRequest  = new getOperingByPkIdRequest();
        getOperingByPkIdRequest.setAccountPkId(BaseApplication.getAccount().getPkId());
        getOperingByPkIdRequest.setPkId(pkid1);
        System.out.println(getOperingByPkIdRequest.toString());
        samplePresenter.BindPresentView(this);
        samplePresenter.onCreate();
        samplePresenter.getOperatingByPkIdPresenterResponseInfo(getOperingByPkIdRequest);
        return marketList;
    }
}
